﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using EHTWebsite.Code;
using EHTWebsiteProject.Code.Entity;

namespace EHTWebsiteProject.Code.BLL
{
    public class ThamSoProvider
    {
        /// <summary>
        /// Ham lay tham so nhom san pham theo ID
        /// </summary>
        /// <param name="pGroupProductsID"></param>
        /// <returns></returns>
        public static ParaGroupProducts GetParaGroupProducts(int pGroupProductsID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_GetParaGroupProducts";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@GroupProductsID", pGroupProductsID));
            DataSet ds =  DataProvider.ExecuteDataSet(cmd);
            ParaGroupProducts theParaGroupProducts = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theParaGroupProducts = new ParaGroupProducts();
                theParaGroupProducts.Columns = Int32.Parse(ds.Tables[0].Rows[0]["Columns"].ToString());
                theParaGroupProducts.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                theParaGroupProducts.DisplayThumb = ds.Tables[0].Rows[0]["DisplayThumb"].ToString();
                theParaGroupProducts.GroupName = ds.Tables[0].Rows[0]["GroupName"].ToString();
                theParaGroupProducts.NumIntro = Int32.Parse(ds.Tables[0].Rows[0]["NumIntro"].ToString());
                theParaGroupProducts.GroupProductsID = Int32.Parse(ds.Tables[0].Rows[0]["GroupProductsID"].ToString());
                theParaGroupProducts.Hover = ds.Tables[0].Rows[0]["Hover"].ToString();
                theParaGroupProducts.ImgAlign = ds.Tables[0].Rows[0]["ImgAlign"].ToString();
                theParaGroupProducts.NumProducts = Int32.Parse(ds.Tables[0].Rows[0]["NumProducts"].ToString());
                theParaGroupProducts.Pagination = ds.Tables[0].Rows[0]["Pagination"].ToString();
                theParaGroupProducts.WidthThumb = ds.Tables[0].Rows[0]["WidthThumb"].ToString();  
            }
            return theParaGroupProducts;
        }
        
        /// <summary>
        /// Ham update tham so cho nhom san pham
        /// </summary>
        /// <param name="psGroupProduct"></param>
        public static void UpdateParaGroupProducts(ParaGroupProducts psGroupProduct)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_UpdateParaGroupProducts";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@GroupProductsID", psGroupProduct.GroupProductsID));
            cmd.Parameters.Add(new SqlParameter("@GroupName", psGroupProduct.GroupName));
            cmd.Parameters.Add(new SqlParameter("@Description", psGroupProduct.Description));
            cmd.Parameters.Add(new SqlParameter("@NumIntro", psGroupProduct.NumIntro));
            cmd.Parameters.Add(new SqlParameter("@Columns", psGroupProduct.Columns));
            cmd.Parameters.Add(new SqlParameter("@NumProducts", psGroupProduct.NumProducts));
            cmd.Parameters.Add(new SqlParameter("@Pagination", psGroupProduct.Pagination));
            cmd.Parameters.Add(new SqlParameter("@WidthThumb", psGroupProduct.WidthThumb));
            cmd.Parameters.Add(new SqlParameter("@DisplayThumb", psGroupProduct.DisplayThumb));
            cmd.Parameters.Add(new SqlParameter("@ImgAlign", psGroupProduct.ImgAlign));
            cmd.Parameters.Add(new SqlParameter("@Hover", psGroupProduct.Hover));
            DataProvider.ExecuteNoneQuery(cmd);

        }

        /// <summary>
        /// Ham lay tham so san pham theo ID
        /// </summary>
        /// <param name="pParaProductsID"></param>
        /// <returns></returns>
        public static ParaProducts GetParaProducts(int pParaProductsID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_GetParaProducts";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@ParaProductsID", pParaProductsID));
            DataSet ds =  DataProvider.ExecuteDataSet(cmd);

            ParaProducts theParaProducts = null;
            if (ds.Tables[0].Rows.Count > 0)
            {
                theParaProducts = new ParaProducts();
                theParaProducts.Columns = Int32.Parse(ds.Tables[0].Rows[0]["Columns"].ToString());
                theParaProducts.DisplayImg = ds.Tables[0].Rows[0]["DisplayImg"].ToString();
                theParaProducts.DisplayPrice = ds.Tables[0].Rows[0]["DisplayPrice"].ToString();
                theParaProducts.DisplayThumbnail = ds.Tables[0].Rows[0]["DisplayThumbnail"].ToString();
                theParaProducts.NumIntro = Int32.Parse(ds.Tables[0].Rows[0]["NumIntro"].ToString());
                theParaProducts.ParaProductsID = Int32.Parse(ds.Tables[0].Rows[0]["ParaProductsID"].ToString());
                theParaProducts.ShowArticle = ds.Tables[0].Rows[0]["ShowArticle"].ToString();
                theParaProducts.ShowNavigation = ds.Tables[0].Rows[0]["ShowNavigation"].ToString();
                theParaProducts.ShowRelation = ds.Tables[0].Rows[0]["ShowRelation"].ToString();
                theParaProducts.WithThumb = ds.Tables[0].Rows[0]["WithThumb"].ToString();                
            }
            return theParaProducts;
        }

        /// <summary>
        /// Ham update cac tham so cua san pham
        /// </summary>
        /// <param name="psProduct"></param>
        public static void UpdateParaProducts(ParaProducts psProduct)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_UpdateParaProducts";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@ParaProductsID", psProduct.ParaProductsID));
            cmd.Parameters.Add(new SqlParameter("@ShowArticle", psProduct.ShowArticle));
            cmd.Parameters.Add(new SqlParameter("@ShowNavigation", psProduct.ShowNavigation));
            cmd.Parameters.Add(new SqlParameter("@DisplayImg", psProduct.DisplayImg));
            cmd.Parameters.Add(new SqlParameter("@DisplayPrice", psProduct.DisplayPrice));
            cmd.Parameters.Add(new SqlParameter("@DisplayThumbnail", psProduct.DisplayThumbnail));
            cmd.Parameters.Add(new SqlParameter("@ShowRelation", psProduct.ShowRelation));
            cmd.Parameters.Add(new SqlParameter("@WithThumb", psProduct.WithThumb));
            cmd.Parameters.Add(new SqlParameter("@NumIntro", psProduct.NumIntro));
            cmd.Parameters.Add(new SqlParameter("@Columns", psProduct.Columns));
            DataProvider.ExecuteNoneQuery(cmd);
        }

        /// <summary>
        /// Ham lay tham so cua nhom tin tuc theo ID
        /// </summary>
        /// <param name="pParaGroupNewsID"></param>
        /// <returns></returns>
        public static DataSet GetParaGroupNews(int pParaGroupNewsID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_GetParaGroupPNews";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@ParaGroupNewsID", pParaGroupNewsID));
            return DataProvider.ExecuteDataSet(cmd);

        }

        /// <summary>
        /// Ham update lai tham so cua nhom tin tuc
        /// </summary>
        /// <param name="psGroupNews"></param>
        public static void UpdateParaGroupNews(ParaGroupNews psGroupNews)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_UpdateParaGrouPNews";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@ParaGroupNewsID", psGroupNews.ParaGroupNewsID));
            cmd.Parameters.Add(new SqlParameter("@NewsOrder", psGroupNews.NewsOrder));
            cmd.Parameters.Add(new SqlParameter("@NewsName", psGroupNews.NewsName));
            cmd.Parameters.Add(new SqlParameter("@Desciption", psGroupNews.Desciption));
            cmd.Parameters.Add(new SqlParameter("@NumIntro", psGroupNews.NumIntro));
            cmd.Parameters.Add(new SqlParameter("@Columns", psGroupNews.ParaGroupNewsID));
            cmd.Parameters.Add(new SqlParameter("@Pagination", psGroupNews.Pagination));
            cmd.Parameters.Add(new SqlParameter("@DisplayIntroText", psGroupNews.DisplayIntroText));
            cmd.Parameters.Add(new SqlParameter("@NumChar", psGroupNews.NumChar));
            cmd.Parameters.Add(new SqlParameter("@DisplayLinkReamore", psGroupNews.DisplayLinkReamore));
            cmd.Parameters.Add(new SqlParameter("@DisplayThumbnail", psGroupNews.DisplayThumbnail));
            cmd.Parameters.Add(new SqlParameter("@WidthOfThumb", psGroupNews.WidthOfThumb));
            cmd.Parameters.Add(new SqlParameter("@ImgAlign", psGroupNews.ImgAlign));
            cmd.Parameters.Add(new SqlParameter("@Hover", psGroupNews.Hover));
            DataProvider.ExecuteDataSet(cmd);
        }

        /// <summary>
        /// Ham lay tham so tin tuc theo ID
        /// </summary>
        /// <param name="pParaNewsID"></param>
        /// <returns></returns>
        public static ParaNews GetParaNews(int pParaNewsID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_GetParaPNews";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@ParaNewsID", pParaNewsID));
            DataSet ds= DataProvider.ExecuteDataSet(cmd);
            ParaNews theParaNews = new ParaNews();
            if (ds.Tables[0].Rows.Count > 0)
            {
                theParaNews.Columns = Int32.Parse(ds.Tables[0].Rows[0]["Columns"].ToString());
                theParaNews.DisplayImage = ds.Tables[0].Rows[0]["DisplayImage"].ToString();
                theParaNews.DisplayIntroText = ds.Tables[0].Rows[0]["DisplayIntroText"].ToString();
                theParaNews.DisplayReadMore = ds.Tables[0].Rows[0]["DisplayReadMore"].ToString();
                theParaNews.DisplayThumb = ds.Tables[0].Rows[0]["Columns"].ToString();
                theParaNews.Numchar = ds.Tables[0].Rows[0]["Numchar"].ToString();
                theParaNews.NumIntro = Int32.Parse(ds.Tables[0].Rows[0]["NumIntro"].ToString());
                theParaNews.Pagination = ds.Tables[0].Rows[0]["Pagination"].ToString();
                theParaNews.ParaNewsID = Int32.Parse(ds.Tables[0].Rows[0]["ParaNewsID"].ToString());
                theParaNews.ShowArticle = ds.Tables[0].Rows[0]["ShowArticle"].ToString();
                theParaNews.ShowArticleRelation = ds.Tables[0].Rows[0]["ShowArticleRelation"].ToString();
                theParaNews.ShowNavigation = ds.Tables[0].Rows[0]["Columns"].ToString();
                theParaNews.WidthOfThumb = Int32.Parse(ds.Tables[0].Rows[0]["WidthOfThumb"].ToString());
            }
            return theParaNews;
        }
        public static void UpdateParaNews(ParaNews psNews)
        {

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "proc_UpdateParaPNews";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@ParaNewsID", psNews.ParaNewsID));
            cmd.Parameters.Add(new SqlParameter("@ShowArticle", psNews.ShowArticle));
            cmd.Parameters.Add(new SqlParameter("@ShowNavigation", psNews.ShowNavigation));
            cmd.Parameters.Add(new SqlParameter("@DisplayImage", psNews.DisplayImage));
            cmd.Parameters.Add(new SqlParameter("@ShowArticleRelation", psNews.ShowArticleRelation));
            cmd.Parameters.Add(new SqlParameter("@DisplayIntroText", psNews.DisplayIntroText));
            cmd.Parameters.Add(new SqlParameter("@Numchar", psNews.Numchar));
            cmd.Parameters.Add(new SqlParameter("@DisplayReadMore", psNews.DisplayReadMore));
            cmd.Parameters.Add(new SqlParameter("@DisplayThumb", psNews.DisplayThumb));
            cmd.Parameters.Add(new SqlParameter("@WidthOfThumb", psNews.WidthOfThumb));
            cmd.Parameters.Add(new SqlParameter("@NumIntro", psNews.NumIntro));
            cmd.Parameters.Add(new SqlParameter("@Columns", psNews.Columns));
            cmd.Parameters.Add(new SqlParameter("@Pagination", psNews.Pagination));
            DataProvider.ExecuteNoneQuery(cmd);
        }
    }
}